package cn.com.sparkle.paxos.event;

import cn.com.sparkle.paxos.paxosinstance.InstancePaxosInstance;

public abstract class ExecutingInstanceChangeEvent implements Event {
	private final static int ENTRY_EXECUTION = 1;
	private final static int EXIT_EXECUTION = 2;

	@Override
	public void event(Object... args) {
		int i = (Integer) args[0];
		switch (i) {
		case ENTRY_EXECUTION:
			entryExecution((InstancePaxosInstance) args[1]);
			break;
		case EXIT_EXECUTION:
			exitExecution((InstancePaxosInstance) args[1]);
			break;
		}
	}

	public final static void doEntryExecutionEvent(EventsManager eventsManager,
			InstancePaxosInstance instance) {
		eventsManager.doEvent(ExecutingInstanceChangeEvent.class,
				ENTRY_EXECUTION, instance);
	}

	public final static void doExitExecutionEvent(EventsManager eventsManager,
			InstancePaxosInstance instance) {
		eventsManager.doEvent(ExecutingInstanceChangeEvent.class,
				EXIT_EXECUTION, instance);
	}

	public abstract void entryExecution(InstancePaxosInstance instance);

	public abstract void exitExecution(InstancePaxosInstance instance);
}
